var add,edit,setVal,reset;
require(['select2', 'date','layout','validator'], function() {
	var $formData = $('#formData');	
	$formData .initForm();

	add = function(fn) {
		addOrUpdate("/lineInfo/addLineInfo.htm",fn);
	};
	
	edit = function(fn) {
		addOrUpdate("/lineInfo/uptLineInfo.htm",fn);
	};
	
	setVal = function (lineId){
		$.ajaxExt({
			url :"/lineInfo/getLineInfoByLineId.htm",
			data : {'lineId' : lineId}
		}).done(function(data){
			$formData.setValues(data);
		});
	};
	
	reset = function (){
		$formData.reset($formData);
	};
	
	function addOrUpdate(url,callBack){
		var result = $.validator($formData);
		$.ajaxExt({
			url: '/baseOrgan/getBaseOrganList.htm'
		}).done(function(data){
			$.each(data, function(i, res){
				if($("input[name='organId']").val() == res.organId){
					$("input[name='corpId']").val(res.corpId);
					if(result){
			    		$.ajaxExt({
			    			url : url,
			    			data : $formData.getValues()
			    		}).done(function(){
			    			callBack();
			    		});
			    	}
					return;
				}
			});
		});
	}
});